﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HZ.Supervise.IBLL;
using HZ.Supervise.Model;
using HZ.Supervise.Model.Enum;
using HZ.Supervise.Model.View;

namespace HZ.Supervise.Web.Secondphase.NewReport
{
    public partial class CompanyPSL_SC : BasePage
    {
        HZ.Supervise.IBLL.IExecuteContext iEC = HZ.Supervise.BLLFactory.ExecuteContext();
        string source = "";

        public CompanyPSL_SC()
        {
            this.ModuleNo = Module.生产企业汇总统计.ToString();
            this.PageOperateType = OperateType.医疗机构汇总统计.ToString();
        }


        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.AreaControl1.InitAreaID = CurrentAccount.GetUser().Org.Area.AreaID;
         
                CompanyPSL_SC_huizong_DataBind();
                CompanyPSL_SC_DataBind();
            }
        }

        /// <summary>
        /// 绑定数据方法    县区
        /// 董辉
        /// 2011-3-30 19:18
        /// </summary>
        private void CompanyPSL_SC_DataBind()
        {
            SuperviseQuery vs = new SuperviseQuery();
            vs = Queryby();
            vs.Flag = "0";
            int t = 0;
            HZ.Supervise.IBLL.IExecuteContext iEC = HZ.Supervise.BLLFactory.ExecuteContext();

            System.Data.DataTable dt = iEC.ExecutePagePSL_SC(vs, this.AspNetPager_CompanyPSL_SC.CurrentPageIndex, AspNetPager_CompanyPSL_SC.PageSize, out t);

            CompanyPSL_SC_hz.RecordCount = t;

            this.gvwxianquInfo.PageSize = AspNetPager_CompanyPSL_SC.PageSize;

            this.gvwxianquInfo.DataSource = dt;

            this.gvwxianquInfo.DataBind();
            
        }
        /// <summary>
        /// 查询条件
        /// </summary>
        /// <returns></returns>
        private SuperviseQuery Queryby()
        {
            SuperviseQuery vs = new SuperviseQuery();
            vs.Append = OrderFileds.SelectedValue + " " + OrderType.SelectedValue;
            vs.CompanyName_PS = txtCompanyName_SC.Text.Trim();
            if (!string.IsNullOrEmpty(txtStratTime.Text))
            {
                vs.PlanTimeFrom = DateTime.Parse(txtStratTime.Text.Trim());

            }
            if (!string.IsNullOrEmpty(txtEndTime.Text))
            {
                vs.PlanTimeTo = Convert.ToDateTime(txtEndTime.Text.Trim());

            }
            vs.AreaID = AreaControl1.SelectedAreaID;
            string Level = string.Empty;
            for (int i = 0; i < cblboxlist.Items.Count; i++)
            {
                if (cblboxlist.Items[i].Selected == true)
                {
                    Level += "'" + cblboxlist.Items[i].Value + "',";
                }
            }


            if (!string.IsNullOrEmpty(Level))
            {
                vs.Levels = Level.Substring(0, Level.Length - 1);
            }


            string isCountry = string.Empty;
            for (int i = 0; i < chkIsCountry.Items.Count; i++)
            {
                if (chkIsCountry.Items[i].Selected == true)
                {
                    isCountry += "'" + chkIsCountry.Items[i].Value + "',";
                }
            }


            if (!string.IsNullOrEmpty(isCountry))
            {
                vs.IsCountry = isCountry.Substring(0, isCountry.Length - 1);
            }
            return vs;
        }

        /// <summary>
        /// 绑定    汇总
        /// by 张雄 2011.5.26
        /// </summary>
        private void CompanyPSL_SC_huizong_DataBind()
        {
            SuperviseQuery vs = new SuperviseQuery();
            vs = Queryby();
            vs.Flag = "1";
            int t = 0;
            HZ.Supervise.IBLL.IExecuteContext iEC = HZ.Supervise.BLLFactory.ExecuteContext();

            System.Data.DataTable dt = iEC.ExecutePagePSL_SC(vs, this.CompanyPSL_SC_hz.CurrentPageIndex, CompanyPSL_SC_hz.PageSize, out t);

            CompanyPSL_SC_hz.RecordCount = t;

            this.gvwPSLInfo.PageSize = CompanyPSL_SC_hz.PageSize;

            this.gvwPSLInfo.DataSource = dt;

            this.gvwPSLInfo.DataBind();
            
        }

        /// <summary>
        /// 查询数据事件
        /// 董辉
        /// 2011-3-30 19:17
        /// </summary>
        /// <param name="sender">事件发送源</param>
        /// <param name="e">事件参数</param>
        protected void btn_chaxun_Click(object sender, EventArgs e)
        {
            //县区
            AspNetPager_CompanyPSL_SC.CurrentPageIndex = 1;
            //汇总
            CompanyPSL_SC_hz.CurrentPageIndex = 1;
        }

        /// <summary>
        /// 分页事件    县区
        /// 董辉
        /// 2011-3-30 19:19
        /// </summary>
        /// <param name="sender">事件发送源</param>
        /// <param name="e">事件参数</param>
        protected void CompanyPSL_SC_PageChanged(object sender, EventArgs e)
        {
            CompanyPSL_SC_huizong_DataBind();
            CompanyPSL_SC_DataBind();
            //
            this.divTable.Visible = true;
            this.divTable.Attributes.Add("style", "display:block");
            this.Page.ClientScript.RegisterStartupScript(this.GetType(), "myscript", "<script>document.getElementById(\"btnShowImg\").value = \"隐藏县区数据\";</script>");

        }

        /// <summary>
        /// 导出数据事件    县区
        /// 董辉
        /// 2011-3-30 19:19
        /// </summary>
        /// <param name="sender">事件发送源</param>
        /// <param name="e">事件参数</param>
        protected void btnExcel_Click(object sender, EventArgs e)
        {


            //System.Data.DataTable dt = iEC.ExecutePagePSL_SC(0, areaid, companyname, source, orderby, 0, 0, out t);

            SuperviseQuery vs = new SuperviseQuery();
            vs = Queryby();
            vs.Flag = "0";
            int t = 0;
            HZ.Supervise.IBLL.IExecuteContext iEC = HZ.Supervise.BLLFactory.ExecuteContext();

            System.Data.DataTable dt = iEC.ExecutePagePSL_SC(vs, 1, 0, out t);


            ExportFile.Instance.ExportData(dt, gvwxianquInfo, this.Page);
        }

        /// <summary>
        /// 分页汇总
        /// by张雄  2011.5.26
        /// </summary>
        /// <param name="sender">事件发送源</param>
        /// <param name="e">事件参数</param>
        protected void CompanyPSL_SC_hz_PageChanged(object sender, EventArgs e)
        {
            CompanyPSL_SC_huizong_DataBind();
            this.divTable.Visible = true;
            this.divTable.Attributes.Add("style", "display:block");
            this.Page.ClientScript.RegisterStartupScript(this.GetType(), "myscript", "<script>document.getElementById(\"btnShowImg\").value = \"隐藏县区数据\";</script>");
        }

        /// <summary>
        /// 导出    汇总
        /// by张雄  2011.5.26
        /// </summary>
        /// <param name="sender">事件发送源</param>
        /// <param name="e">事件参数</param>
        protected void btnExcelhz_Click(object sender, EventArgs e)
        {
            SuperviseQuery vs = new SuperviseQuery();
            vs = Queryby();
            vs.Flag = "1";
            HZ.Supervise.IBLL.IExecuteContext iEC = HZ.Supervise.BLLFactory.ExecuteContext();
            int t = 0;
            System.Data.DataTable dt = iEC.ExecutePagePSL_SC(vs, 1, 0, out t);
            ExportFile.Instance.ExportData(dt, gvwPSLInfo, this.Page);
        }
    }
}
